package cn.iocoder.yudao.module.reading.dal.mysql.assignment;

import cn.iocoder.yudao.framework.mybatis.core.mapper.BaseMapperX;
import cn.iocoder.yudao.framework.mybatis.core.query.LambdaQueryWrapperX;
import cn.iocoder.yudao.module.reading.dal.dataobject.assignment.ClassAssignmentDO;
import org.apache.ibatis.annotations.Mapper;

import java.util.List;

/**
 * 班级作业 Mapper
 *
 * @author 芋道源码
 */
@Mapper
public interface ClassAssignmentMapper extends BaseMapperX<ClassAssignmentDO> {

    /**
     * 根据班级ID查询作业列表
     *
     * @param classId 班级ID
     * @return 作业列表
     */
    default List<ClassAssignmentDO> selectByClassId(Long classId) {
        return selectList(new LambdaQueryWrapperX<ClassAssignmentDO>()
                .eq(ClassAssignmentDO::getClassId, classId)
                .eq(ClassAssignmentDO::getIsActive, true)
                .orderByDesc(ClassAssignmentDO::getAssignmentDate)
                .orderByDesc(ClassAssignmentDO::getCreateTime));
    }

    /**
     * 根据创建者ID查询管理的班级作业
     *
     * @param creatorId 创建者ID
     * @return 作业列表
     */
    default List<ClassAssignmentDO> selectByCreatorId(Long creatorId) {
        return selectList(new LambdaQueryWrapperX<ClassAssignmentDO>()
                .eq(ClassAssignmentDO::getCreatorId, creatorId)
                .eq(ClassAssignmentDO::getIsActive, true)
                .orderByDesc(ClassAssignmentDO::getAssignmentDate)
                .orderByDesc(ClassAssignmentDO::getCreateTime));
    }

    /**
     * 根据班级ID和创建者ID查询作业列表
     *
     * @param classId   班级ID
     * @param creatorId 创建者ID
     * @return 作业列表
     */
    default List<ClassAssignmentDO> selectByClassIdAndCreatorId(Long classId, Long creatorId) {
        return selectList(new LambdaQueryWrapperX<ClassAssignmentDO>()
                .eq(ClassAssignmentDO::getClassId, classId)
                .eq(ClassAssignmentDO::getCreatorId, creatorId)
                .eq(ClassAssignmentDO::getIsActive, true)
                .orderByDesc(ClassAssignmentDO::getAssignmentDate)
                .orderByDesc(ClassAssignmentDO::getCreateTime));
    }

}
